<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script src="/html/js/util.js"></script>
    <script>
        window.onload = function () {
            init();
        }

        async function init() {
            let pageInfo = await ajaxGet("/order/findByItemDeBoy");
            let orderStr = "";
            for (let i = 0; i < pageInfo.length; i++) {
                let obj = pageInfo[i];
                orderStr += `<tr>
                           <td>${obj.id}</td>
                           <td>${obj.name}</td>
                           <td>${obj.phone}</td>
                           <td>${obj.money}</td>
                           <td><a onclick="update(${obj.id})">结账</a></td>
                           </tr>`
            }
            getObject("ordertb").innerHTML = orderStr;
        }

        async function update(orderId){
            let infoObj = await ajaxGet("/order/findById", {id: orderId});
            if (infoObj.status=="发货中") {
                let info = await ajaxGet("/order/finish", {id: orderId});
                if (info == "ok") {
                    await init();
                }
            }else {
                alert("当前订单状态已经不是'发货中'状态，无法做出更改")
            }
        }

    </script>
</head>
<body>
<div style="margin-left: 100px;margin-top: 100px">
    <table border="1" cellpadding="0">
        <thead>
        <tr>
            <th>订单号</th>
            <th>收货人</th>
            <th>收货人电话</th>
            <th>订单总价</th>
            <th>结账</th>
        </tr>
        </thead>
        <tbody id="ordertb"></tbody>
    </table>
</div>
</body>
</html>